
location <- "/Users/dillonlaaker/Box/Stability/"
setwd(paste(location, "data/datasets", sep = ""))

completeFun <- function(data, desiredCols) {
  completeVec <- complete.cases(data[, desiredCols])
  return(data[completeVec, ])
}


plot <- read.csv("figure1_raw.csv")
plot <- plot[, c(3,8)]
colnames(plot) <- c("year", "X1")
plot$stab <- ifelse(plot$X1 == 0, 1, 0)
plot$flex <- ifelse(plot$X1 == 0, 0, 1)

plot$v1 <- 1
plot <- within(plot, {total = ave(v1, year, FUN=sum)} )
plot <- within(plot, {flex = ave(flex, year, FUN=sum)} )
plot <- within(plot, {stab = ave(stab, year, FUN=sum)} )

plot$v2 <- ave(plot$v1, plot$year, FUN = seq_along)
plot$v2[plot$v2>1] <- NA
plot <- completeFun(plot, "v2")
plot <- plot[order(plot$year), ]
plot <- plot[, c("year", "flex", "stab", "total")]


setwd("/Users/dillonlaaker/Box/Stability/draft")
pdf("figure1n.pdf", height=6, width=12) 
plot(plot$year, plot$stab, lwd=3, ylab="Number of Publications", xlab="Year", type="l", yaxt="n", xaxt="n", bty="n", xaxs="i", yaxs="i", lty=2, col="gray", ylim=c(0,10), xlim=c(1993,2019))
lines(plot$year, plot$flex, col="black", lwd=3)
axis(side=1, at=c(1993:2019), lab=c("1993", "", "", "", "", "1998", "", "", "", "", "2003", "", "", "", "", "2008", "", "", "", "", "2013", "", "", "", "", "2018", ""), lty=1, cex.axis=1)
axis(side=2, at=c(0:10), lab=c("0", "", "2", "", "4", "", "6", "", "8", "", "10"), lty=1, cex.axis=1)
legend("topleft", c("Stable","Unstable"), lty = c(2,1), bty="n")
dev.off()

